package com.huluobo.a2307douyindemo.demo.viewbinding

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding

/**
 *  Created by LC on 2025/9/11.
 */
abstract class BaseFragment2<T : ViewBinding> : Fragment() {
    lateinit var binding: T

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = getViewBinding(inflater, container, savedInstanceState)
        return binding.root
    }

    //由于onCreateView方法中视图可能还未完全创建完毕,所以初始化视图和初始化数据的操作需要放到onViewCreated方法中
    //这样能保证数据不泄漏,否则有可能会造成内存泄漏
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        initData()
    }

    abstract fun initData()

    abstract fun initView()

    abstract fun getViewBinding(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): T

}